package com.framework.modules.base.dao;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.framework.modules.base.entity.UserIncomeHistoryEntity;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * 公会收益明细表 
 * 
 * @author MIT
 * @email litmiss@gmail.com
 * @date 2020-11-08 13:41:01
 */
public interface UserIncomeHistoryDao extends BaseMapper<UserIncomeHistoryEntity> {
    /**
     * 根据uid，获取用户收益
     * @param uid
     * @return
     */
    @MapKey("type")
    @Select("SELECT uih.type,sum(uih.income_money) as income_money from tb_user_income_history uih where state=0 " +
            "  and uih.uid=#{uid} group by uih.type ")
    Map<String,UserIncomeHistoryEntity> getMyIncomeMap(@Param("uid") Integer uid);

    @MapKey("type")
    List<UserIncomeHistoryEntity> getMyIncome(@Param("uid") Integer uid, @Param("type") String type);

    @Update("update tb_user_income_history set state=#{state} where uid=#{uid} and type=#{type}")
    Integer updateMyIncomeState(@Param("uid") Integer uid,@Param("type")String type,@Param("state")Integer state);

    List<Map<String,Object>> queryLiveIncomeHistory(Pagination page, @Param("params") Map<String,Object> params);
	
}
